<template>
    <div class='boss'>
       <!-- 新闻动态预览 -->
       <div class="topbtn">
          <el-button class="addBtn2" @click="goback">{{prevPageRoute.includes('/newsDetail/newsedit') ? '返回编辑': '返回列表'}}</el-button>
       </div>
       <div class="title">
            <h3>{{newsData.noticeTitle}}</h3>
       </div>
       <div class="futitle">
          <span style="margin-right: 10px;">{{  dayjs().format('YYYY-MM-DD HH:mm:ss') }}</span>
          <span>编辑</span>
          <span style="margin: 0 5px 0 5px;">|</span>
          <span>{{userInfo.userName}}</span>
       </div>
       <div class="wenzhang" v-html="newsData.noticeContent"></div>
    </div>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import { useRouter, useRoute } from 'vue-router';
import dayjs from 'dayjs'
import {useListStore} from '@/store/modules/news.js'
const router = useRouter();
const route = useRoute();
const newsData = ref({});
const userInfo = ref({
  userName:''
})
const newsPut = useListStore()

const prevPageRoute = ref('') // 上级页面路径，/newsDetail/newsedit 点击编辑弹窗的预览过来是返回编辑
// 监听当前路由变化
router.afterEach((to, from) => {
  if (from.fullPath) {
    // console.log('上级页面路径:', from.fullPath);
    prevPageRoute.value = from.fullPath
  }
});

const goback = ()=>{
  newsPut.fetchList(newsData.value)
  router.go(-1)
}

onMounted(()=>{
  newsData.value = newsPut.listData
  console.log(newsPut.listData,'打印pinia传过来的数据');
  
  userInfo.value =  JSON.parse(localStorage.getItem('userInfo'))
})
</script>

<style lang='scss' scoped>
.boss{
  padding: 16px;
  .title{
      text-align: center;
      font-size: 20px;
      margin: 20px 0 20px 0;
  }
  .futitle{
     padding-bottom: 16px;
     border-bottom: 1px solid #e5e6eb;
  }
}
</style>
